import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_search_enter.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/entities/inspec/ins_task_detail_entity.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/hazard_investigation/supplementary_inspection/supplementary_inspection_controller.dart';

/// 隐患排查-补检任务页面
class SupplementaryInspectionPage extends StatelessWidget {
  SupplementaryInspectionPage({super.key});

  final controller = Get.put(SupplementaryInspectionController());

  ///获取条件搜索项
  Widget _getSearchConditionWidget() {
    return Row(
      children: [
        Expanded(
            child: CustomSearchEnter(
          height: 38.w,
          hintText: '输入任务名称',
          text: controller.search,
          onCallBack: (value) {
            controller.search = value;
            controller.refreshPage();
          },
        )),
        // AppGaps.hGap8,
        // _screen(),
      ],
    );
  }

  ///筛选
  Widget _screen() {
    return Container(
      width: 38.w,
      height: 38.w,
      alignment: Alignment.center,
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
      child: SvgPicture.asset(
        AppImages.icon_search_screen,
        width: 16.w,
      ),
    ).click(() {});
  }

  /// 获取列表对象-单元-事件显示
  String _getText(InsTaskDetailEntity item) {
    return '${item.riskObjectName}${item.riskUnitName == '' ? '' : '/${item.riskUnitName}'}${item.riskEventName == '' ? '' : '/${item.riskEventName}'}';
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            appBar: CustomAppBar(
              titleText: '补检任务',
            ),
            body: Container(
              color: const Color(0xffF5F5F6),
              padding: EdgeInsets.symmetric(horizontal: 14.w),
              child: Column(
                children: [
                  AppGaps.vGap10,
                  _getSearchConditionWidget(),
                  AppGaps.vGap12,
                  Expanded(
                    child: CustomEasyRefreshList<InsTaskDetailEntity>(
                      key: controller.globalKey,
                      dataLoad: (pageIndex, pageSize, {String? search}) async {
                        return controller.getListData(pageIndex, pageSize);
                      },
                      itemBuilder: (InsTaskDetailEntity item, int index) {
                        return CustomTitleChartPage(
                          title: item.troubleshootContent ?? '------',
                          titleRightWidget: Visibility(
                              child: Container(
                            margin: EdgeInsets.only(right: 16.w),
                            child: SvgPicture.asset(
                              AppImages.icon_supplementary_inspection,
                              width: 43.w,
                              height: 20.w,
                              // colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn),
                            ),
                          )),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Row(
                                children: [
                                  Text(
                                    '到期时间：',
                                    style: TextStyle(
                                      fontSize: 13.sp,
                                      height: 1.2,
                                      fontWeight: FontWeight.w400,
                                      color: const Color(0xffA5A6B5),
                                    ),
                                  ),
                                  Expanded(
                                      child: Text(
                                    item.supplementaryInspectionTime ?? '',
                                    textAlign: TextAlign.right,
                                    style: TextStyle(
                                      fontSize: 12.sp,
                                      height: 1.2,
                                      fontWeight: FontWeight.w400,
                                      color: const Color(0xff495061),
                                    ),
                                  ))
                                ],
                              ),
                              AppGaps.vGap10,
                              Text(
                                _getText(item),
                                style: TextStyle(color: const Color(0xff495061), height: 1.2, fontWeight: FontWeight.w400, fontSize: 12.sp),
                              ),
                              AppGaps.vGap10,
                              Row(
                                children: [
                                  Text(
                                    '管控措施：',
                                    style: TextStyle(color: const Color(0xffA5A6B5), height: 1.2, fontWeight: FontWeight.w400, fontSize: 12.sp),
                                  ),
                                  Expanded(
                                    child: Text(
                                      item.riskMeasureDesc ?? '',
                                      style: TextStyle(color: const Color(0xff495061), height: 1.2, fontWeight: FontWeight.w400, fontSize: 12.sp),
                                    ),
                                  )
                                ],
                              )
                            ],
                          ),
                        ).clickOnce(() {
                          controller.toDetailsPage(item.id!);
                        });
                      },
                    ),
                  ),
                ],
              ),
            ),
          );
        });
  }
}
